<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>javascript验证</title>
    <script>
        function check() {
            var name = document.getElementById("put1");
            var nouser = document.getElementById("nouser");
            var haveuser = document.getElementById("haveuser");
            nouser.style.display="none";
            haveuser.style.display="none";
            if(0 != name.length){
                var char = name.value.charAt(0);
                console.log(char);
                if('a' == char || 'A' == char)
                    haveuser.style.display="inline";
                else
                    nouser.style.display="inline";

            }
        }
    </script>
</head>
<body>
<input id="put1">
<button onclick="check()">验证</button>
<span id="nouser" style="display:none">没有这个用户</span>
<span id="haveuser" style="display:none">用户已经存在</span>
</body>
</html>